/*************************************************************************
	> File Name: composite.h
	> Author: ma6174
	> Mail: ma6174@163.com 
	> Created Time: 2021年12月02日 星期四 21时47分21秒
 ************************************************************************/

#include<iostream>
#include <string>
#include <list>

//公司抽象接口
class Company
{
public:
	Company(std::string n) : name(n) {}

	virtual void add(Company* c) = 0;
	virtual void remove(Company* c) = 0;
	virtual void display(int depth) = 0;
	virtual void lineOfDuty() = 0;

protected:
	std::string name;
};

//枝节点
class ConcreteCompany : public Company
{
public:
	using Company::Company;

	virtual void add(Company* c)
	{
		children.push_back(c);
	}

	virtual void remove(Company* c)
	{
		children.remove(c);
	}

	virtual void display(int depth)
	{
		std::cout << std::string(depth, '-') << name << std::endl;
		for (auto elem : children)
			elem->display(depth + 2);
	}

	virtual void lineOfDuty()
	{
		for (auto elem : children)
			elem->lineOfDuty();
	}

private:
	std::list<Company*> children;
};

//叶节点
class HRDepartment : public Company
{
public:
	using Company::Company;
	
	virtual void add(Company* c) {}
	virtual void remove(Company* c) {}
	virtual void display(int depth)
	{
		std::cout << std::string(depth, '-') << name << std::endl;
	}

	virtual void lineOfDuty()
	{
		std::cout << name << "\t员工招聘培训管理" << std::endl;
	}
};

class FinanceDepartment : public Company
{
public:
	using Company::Company;

	virtual void add(Company* c) {}
	virtual void remove(Company* c) {}
	virtual void display(int depth)
	{
		std::cout << std::string(depth, '-') << name << std::endl;
	}

	virtual void lineOfDuty()
	{
		std::cout << name << "\t公司财务收支管理" << std::endl;
	}
};
